package basic.chapter1;

/**
 * @author Kevin
 * @date 2020/2/20 14:04
 * 编译优化带来的有序性问题,利用双重检查创建单例对象
 *双重检查法
 */
public class Singleton {
    static Singleton instance;
    static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) instance = new Singleton();
            }
        }
        return instance;
    }
}
